/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package cult.ticketing.dao;

import cult.ticketing.bean.House;
import cult.ticketing.jdbc.DB;
import java.util.ArrayList;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.naming.NamingException;
import javax.sql.DataSource;

/**
 *
 * @author 51158282
 */
public class HouseDAO {
    public House getHouseById(int houseId) {
        House house = null;
/**
 * 	private int id;
	private int capacity;
        private int blockOneWidth;
        private int blockTwoWidth;
        private int blockThreeWidth;
        private int houseHeight;
 * 
 * 
 */


        try {
            DataSource ds = DB.getDataSource();
            Connection con = ds.getConnection();
            PreparedStatement pstmt = con.prepareStatement("SELECT * FROM [house] where [id] = ?;");
            pstmt.setInt(1, houseId);
            ResultSet rs = pstmt.executeQuery();
            if (rs != null && rs.next() != false) {
                house = new House();
                house.setId(rs.getInt(1));
                house.setCapacity(rs.getInt(2));
                house.setBlockOneWidth(rs.getInt(3));
                house.setBlockTwoWidth(rs.getInt(4));
                house.setBlockThreeWidth(rs.getInt(5));
                house.setHouseHeight(rs.getInt(6));
                
            }

            if (rs != null)
                rs.close();
            if (pstmt != null)
                pstmt.close();
            if (con != null)
                con.close();
        } catch (javax.naming.NamingException ne) {
            /* ignore */
        } catch (SQLException sqle) {
            /* ignore */
        }

        return house;
    }
}
